package com.simple.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.simple.entity.XmlBean;
import com.simple.utils.XmlUtils;

/**
 * 系统监听器
 * @author 李凯
 * @version v-1.0
 * @date 2017-8-20
 * */
public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("==============simple mvc已注销！==============");
	}

	/**
	 * 初始化mvc框架，完成配置文件解析
	 * @author 李凯
	 * @version v-1.0
	 * @date 2017-8-20
	 * */
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext context = arg0.getServletContext();
		String xmlpath = context.getInitParameter("simple-config");
		String tomcatpath = context.getRealPath("\\");
		try {
			Map<String, XmlBean> map = XmlUtils.simpleXml(tomcatpath+xmlpath);
			context.setAttribute("simple", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("==============simple mvc已加载完成！==============");
	}

}
